<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Configuration</title>
<!-- Required Stylesheets -->
    <script src=".css/demo.js" type="text/javascript"></script>
    <script src="css/jquery.dataTables.js" type="text/javascript"></script>
	<link rel="stylesheet" href="css/table.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/demo.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/button.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/mws.theme.css" type="text/css" media="screen" />
<!-- Theme Stylesheet -->
<!--[if lt IE 9]>
<script type="text/javascript" src="view/templates/temp1/plugins/flot/excanvas.min.js"></script>
<![endif]-->
</head>
<?php 
	
	include_once('process\database.php');
	include_once('process\db.inc');
	include_once('process\face.inc');
	
	if (!file_exists('process\db.inc'))
	{
		echo "Configuration file not found!";
	}
	else
	{
		require_once 'plugin/Config/Config.php';
	}
	if(isset($_POST['btn_submit']))
	{		
		$settings['hostname'] = $_POST['host'];
		$settings['dbname'] = $_POST['dbname'];
		$settings['dbuser'] = $_POST['user'];
		$settings['dbpass'] = $_POST['pass'];
		
		
		$c0 = new Config(); 
		$root0 =& $c0->parseConfig($settings, "PHPArray"); 					
		$options0 = array('name' => 'settings'); 
		// write configuration to file as PHP array 
		$c0->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."process/db.inc", "PHPArray", $options0);	
		
		$face['appID'] = $_POST['appid'];
		$face['secret'] =$_POST['secret'];
		
		$c1 = new Config(); 
		$root1 =& $c1->parseConfig($face, "PHPArray"); 					
		$options1 = array('name' => 'face'); 
		// write configuration to file as PHP array 
		$c1->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."process/face.inc", "PHPArray", $options1);	
		
		$db = new database();
		$sql = explode(';', file_get_contents('db/thomsonvote.sql'));
		foreach ($sql as $key => $val) {
    		$db->SetQuery($val);
    		$db->Query();
		}			
		header("Location:page.php");	
	}		 
?>
<body style="background: url('images/mws-body-bg.png') repeat;">
	<center style="margin: 150px;">
		<form class="mws-form" action="" method="post">
		<table class="mws-datatable-fn mws-table" style="width: 400px !important">		
				<thead>			
					<tr>
						<th colspan="2" rowspan="1" class="sorting">Configuration</th>					
					</tr>
	           </thead>                       
	          <tbody>         
	          	<tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">Host Name</td>
	                <td class="center"><input type="text" class="mws-textinput" name="host" value="<?php echo $settings['hostname']?>" /></td>
	            </tr>
	            <tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">Database Name</td>
	                <td class="center"><input type="text" class="mws-textinput" name="dbname" value="<?php echo $settings['dbname']?>" /></td>
	            </tr>
	            <tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">User Name</td>
	                <td class="center"><input type="text" class="mws-textinput" name="user" value="<?php echo $settings['dbuser']?>" /></td>
	            </tr>
	            <tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">Password</td>
	                <td class="center"><input type="password" class="mws-textinput" name="pass" value="<?php echo $settings['dbpass']?>" /></td>
	            </tr>
	            
	            <tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">App_id</td>
	                <td class="center"><input type="text" class="mws-textinput" name="appid" value="<?php echo $face['appID']?>" /></td>
	            </tr>
	            <tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center">Secret</td>
	                <td class="center"><input type="text" class="mws-textinput" name="secret" value="<?php echo $face['secret']?>" /></td>
	            </tr>
	         	<tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
	                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
	                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
	                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
	                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
	                <td class="center"></td>
	                <td class="center"><input type="submit" value="Update Configuration" class="mws-button green" onclick="return confirm('Are you sure ?');" name="btn_submit" /></td>
	            </tr>
	          </tbody>
	      </table>	  		
		</form>
	</center>
</body>
</html>
